#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
class Solution {
public:
    vector<vector<int>> fourSum(vector<int>& nums, int target) {
        sort(nums.begin(), nums.end());
        vector<vector<int>> v;
        int n = nums.size();
        for (int i = 0; i < n - 3; i++) {
            long long num1 = target - nums[i];
            for (int j = i + 1; j < n - 2; j++) {
                long long num2 = num1 - nums[j];
                int left = j + 1;
                int right = n - 1;
                while (left < right) {
                    int sum = nums[left] + nums[right];
                    if (sum > num2) {
                        right--;
                    }
                    else if (sum < num2) {
                        left++;
                    }
                    else
                    {
                        v.push_back({ nums[i], nums[j], nums[left], nums[right] });
                        left++;
                        right--;
                        while (left < right && nums[left] == nums[left - 1]) {
                            left++;
                        }
                        while (left < right && nums[right] == nums[right + 1]) {
                            right--;
                        }

                    }
                }
                while (j < n - 3 && nums[j] == nums[j + 1]) {
                    j++;
                }
            }
            while (i < n - 4 && nums[i] == nums[i + 1]) {
                i++;
            }
        }
        return v;
    }

};
int main()
{

	return 0;
}